package com.ncloud.resman.service.impl;

import com.ncloud.resman.entity.VirtualNetworkCard;
import com.ncloud.resman.mapper.VirtualNetworkCardMapper;
import com.ncloud.resman.service.SequenceService;
import com.ncloud.resman.service.VirtualNetworkCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by shiqiang on 2017/8/28.
 */
@Service
public class VirtualNetworkCardServiceImpl implements VirtualNetworkCardService{
    @Autowired
    private SequenceService sequenceService;
    @Autowired
    private VirtualNetworkCardMapper virtualNetworkCardMapper;
    @Override
    public int insertVirtualNetworkCard(VirtualNetworkCard virtualNetworkCard) {
        if(virtualNetworkCard.getCardId() == null){
            Long id = sequenceService.getSequence("disk_id_seq");
            virtualNetworkCard.setCardId(id);
        }
        if(virtualNetworkCard.getCreateDate()==null){
            virtualNetworkCard.setCreateDate(new Date());
        }
        return virtualNetworkCardMapper.insertVirtualNetworkCard(virtualNetworkCard);
    }

    @Override
    public int updateVirtualNetworkCard(VirtualNetworkCard virtualNetworkCard) {
        if(virtualNetworkCard.getUpdateDate()==null){
            virtualNetworkCard.setUpdateDate(new Date());
        }
        return virtualNetworkCardMapper.updateVirtualNetworkCard(virtualNetworkCard);
    }

    @Override
    public VirtualNetworkCard getVirtualNetworkCardById(Long cardId) {
        return virtualNetworkCardMapper.getVirtualNetworkCardById(cardId);
    }

    @Override
    public int deleteVirtualNetworkCard(Long cardId) {
        return virtualNetworkCardMapper.deleteVirtualNetworkCard(cardId);
    }

    @Override
    public int updateVirtualNetworkCardState(Long cardId, String state) {
        return virtualNetworkCardMapper.updateVirtualNetworkCardState(cardId,state);
    }

    @Override
    public int deleteVirtualCardByVirtualId(Long virtualId) {
        return virtualNetworkCardMapper.deleteVirtualCardByVirtualId(virtualId);
    }

    @Override
    public List<VirtualNetworkCard> getVirtualNetworkVirtualId(Long virtualId) {
        return virtualNetworkCardMapper.getVirtualNetworkVirtualId(virtualId);
    }

    @Override
    public List<VirtualNetworkCard> getVirtualManageIp(Long virtualId) {
        return virtualNetworkCardMapper.getVirtualManageIp(virtualId);
    }
}
